package awk.jdk8.functionalInterface;


import awk.model.User;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;

/**
 * created with IDEA
 *
 * @author haifeng.wang
 * @since 2019-05-31-18:29
 */
public class BiConsumerTest {
    static List<User> users = new ArrayList<>();
    static User user1 = User.builder().name("穆建国").age(26).salary(1000000).build();
    static User user2 = User.builder().name("钱塘江").age(33).salary(122222).build();
    static {
        users.add(user1);
        users.add(user2);
    }

    public static void main(String[] args) {
        //BiConsumer<Integer, User>  接受两个输入参数，并且不返回任何结果
        BiConsumer<Integer, User> biConsumer = (i,user)-> user.setAge(i+10);
        //方法参数要匹配。至于第二个参数,接收两个参数，并且类型分别是Integer,User
        //users.forEach(user -> biConsumer.accept(user.getAge(),user));
        biConsumer.accept(user1.getAge(),user1);
        System.out.println(user1.getAge());


        //BiFunction<T,U,R>  接受两个输入参数，并且返回一个结果
        BiFunction<Integer,String,User> biConsumer2 = (age,name)-> User.builder().age(age).name(name).build();
        User apply = biConsumer2.apply(user1.getAge(), user1.getName());
        System.out.println(apply);

        //返回年龄更大的人 接受两个统类型的参数，并且返回了同类型的参数
        BinaryOperator<User> binaryOperator = (u,v) -> u.getAge()>v.getAge()? u: v;
        User apply1 = binaryOperator.apply(user1, user2);

    }
}
